<?php include  APP_PATH.'../template/public/header.php'?>
<aside class="main-sidebar">
    <section class="sidebar">
        <?php include APP_PATH.'../template/public/navigation.php'?>
    </section>
</aside>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {$title}
        </h1>

        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
        </ol>
    </section>
    <section class="content">
        <div class="box box-default">
            <div class="box-body" style="font-size: 12px;">
                <form class="layui-form " action="">
                    <div class="layui-form-item">
                        <h3>代理商信息</h3>
                    </div>
                    <input type="text" name="id" lay-verify="required" autocomplete="off"  class="layui-input layui-hide"   disabled value="{$agent.id}" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">代理商账户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入用户名" class="layui-input"   disabled value="{$agent.name}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 代理名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="agent_name" lay-verify="required" placeholder="请输入公司名称" autocomplete="off" class="layui-input" value="{$agent.agent_name}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 公司名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="company_name" lay-verify="required" placeholder="请输入公司名称" autocomplete="off" class="layui-input" value="{$agent.company_name}" >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input" value="{$agent.email}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 资质证明</label>
                        <input type="hidden" name="aptitude_img" id="aptitude_img" value="{$agent.aptitude_img}">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="image1">
                                </div>
                                <button type="button" class="layui-btn layui-btn-primary" id="bannerBtn1"><i class="icon icon-upload3"></i>点击上传图片</button>
                                <p>目前支持 gif | jpg | png 等图片文件上传，文件大小2M以内</p>
                                <p id="demoText1"></p>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 营业执照</label>
                        <input type="hidden" name="license_img" id="license_img" value="{$agent.license_img}">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="image2" >
                                </div>
                                <button type="button" class="layui-btn layui-btn-primary" id="bannerBtn2"><i class="icon icon-upload3"></i>点击上传图片</button>
                                <p>目前支持 gif | jpg | png 等图片文件上传，文件大小2M以内</p>
                                <p id="demoText2"></p>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">  营业执照统一社会信用代码</label>
                        <div class="layui-input-block">
                            <input type="text" name="license_code"  lay-verify="required" placeholder=" 营业执照统一社会信用代码" autocomplete="off" class="layui-input" value="{$agent.license_code}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">  注册地</label>
                        <div class="layui-input-block">
                            <input type="text" name="register_city"  placeholder=" 营业执照统一社会信用代码" autocomplete="off" class="layui-input"  value="{$agent.register_city}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <h3>联系人信息</h3>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="contact"  autocomplete="off" class="layui-input" value="{$agent.contact}">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人手机</label>
                            <div class="layui-input-inline">
                                <input type="tel" name="contact_phone" lay-verify="required|phone" autocomplete="off" class="layui-input" value="{$agent.contact_phone}">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">联系人邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="contact_email" lay-verify="email" autocomplete="off" class="layui-input" value="{$agent.contact_email}">
                            </div>
                        </div>
                    </div>
                </form>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">审核信息</label>
                    <div class="layui-input-block">
                        <textarea id="audit_note" placeholder="请输入审核信息" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-block">
                            <button class="layui-btn" onclick="audit(1)" >审核通过</button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-block">
                            <button class="layui-btn" onclick="audit(2)">审核不通过</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>
    function audit(state) {
        var id='{$agent.id}';
        var audit_note=$('#audit_note').val();
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.post('{:url("")}',{id:id,audit_state:state,audit_note:audit_note},function (res) {
            layer.close(loading);
            if (res.code > 0) {
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                    location.href = res.url;
                });
            } else {
                layer.msg(res.msg, {time: 1800, icon: 2});
            }
        });
    }

    layui.use(['form', 'layedit', 'laydate','upload'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,upload = layui.upload;
        //自定义验证规则
        $('input').attr('disabled','true');
        if("{$agent.aptitude_img}"){
            $('#image1').attr('src', '__IMG_PATH__{$agent.aptitude_img}');
            $('#image1').attr('style','height: 350px;width: 220px')
        }
        if("{$agent.license_img}"){
            $('#image2').attr('src', '__IMG_PATH__{$agent.license_img}');
            $('#image2').attr('style','height: 350px;width: 220px')
        }

        form.verify({
            title: function(value){
                if(value.length < 5){
                    return '标题至少得5个字符啊';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        var uploadInst = upload.render({
            elem: '#bannerBtn1'
            ,url: '{:url("admin/UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#image1').attr('src', result);
                    $('#image1').attr('style','height: 350px;width: 220px')
                });
            },

            done: function(res){
                if(res.code>0){
                    $('#aptitude_img').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }

        });
        //
        var uploadInst1 = upload.render({
            elem: '#bannerBtn2'
            ,url: '{:url("admin/UpFiles/upload")}'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#image2').attr('src', result); //图片链接（base64）
                    $('#image2').attr('style','height: 350px;width: 220px')
                });
            },
            done: function(res){
                if(res.code>0){
                    $('#license_img').val(res.url);
                }else{
                    //如果上传失败
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText2');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst1.upload();
                });
            }
        });
        //监听提交
        form.on('submit(demo1)', function(data){
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('')}", data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
            return false;
        });
    });
</script>
</html>